package sg.edu.ntu.metaweb.storage.data;


import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;

public class Contribution implements Serializable {

	protected User contributor;
	private HashMap<User, Vote> votes;
	
	
	public Contribution(User contributor) {
		this.contributor = contributor;
		votes = new HashMap<User, Vote>();
	}
	
	
	
	public int getRating() {
		int rating = 0;
		
		Iterator<Vote> voteIterator = votes.values().iterator();
		while (voteIterator.hasNext()) {
			rating += voteIterator.next().getValue();
		}
	
		return rating;
	}
	
	public void upvote(User user) {
		vote(user, (byte)+1);
	}
	
	public void downvote(User user) {
		vote(user, (byte)-1);
	}
	
	private void vote(User user, byte value) {
		votes.put(user, new Vote(value));
	}
	
}
